 <script src="${staticPath}/tools/js/moment/moment-with-locales.min.js"></script>
<script src="${staticPath}/plugins/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js"></script>
<script src="${staticPath}/plugins/select2/select2.min.js"></script>


<script>
//审核提交
  function submitAudit(status,flag,page,isReport) {
	 
		  if(isReport==1){
		   var tbAuditReportId = $('#tbAuditReportId').val();
	        if(tbAuditReportId == null || tbAuditReportId == ""){
	           alert("请填写审核报告！");
	           return ; 
	        }
		  }
	   
        var times = $('#times').val();
        
		var uid = $('#uid').val();
		var auditClassify =  $('#auditClassify').val();
		var auditType = $('#auditType').val();
		var auditStatus =  status;
		var auditRemark = $('#auditRemark').val();
		if (auditRemark.trim() == "") {
			$("#tips").text("审核意见不可为空");
			return;
		} else {
			$("#tips").text("");
		}
		$.ajax({
			url : '/crm/auditrecord/insert',
			type : 'post',
			data : {
				uid : uid,
				tbAuditReportId : tbAuditReportId,
				auditClassify : auditClassify,
				auditType : auditType,
				auditStatus : auditStatus,
				auditRemark : auditRemark
			},
			success : function(obj) {
				console.log(obj);
				
				greeting({
					msg : "操作成功!",
					confirm : function() {
						
						window.location ="/crm/auditrecord/"+page;
					}
				  });
			},
			error : function(obj) {
				console.log(obj);
			}
		});
	}    

// 重新填写合同modal
function openInsertModel(uid) {
        $("#contractUid").val(uid);
        var createTime = $("#createTime").val('');
        var payMoney = $("#payMoney").val('');
        var remark = $("#remark").val('');
        $('#contractModal').modal();
}

// 重置
function resetQuery(model,page){

     window.location ="/crm/"+model+"/"+page;   
}
        
  //审核提交
  function submitAudit1(status,flag,page,isReport) {
	 
		  if(isReport==1){
		   var tbAuditReportId = $('#tbAuditReportId').val();
	        if(tbAuditReportId == null || tbAuditReportId == ""){
	           alert("请填写审核报告！");
	           return ; 
	        }
		  }
	   
        var times = $('#times').val();
        
		var uid = $('#uid').val();
		var auditClassify =  $('#auditClassify').val();
		var auditType = $('#auditType').val();
		var auditStatus =  status;
		var auditRemark = $('#auditRemark').val();
		if (auditRemark.trim() == "") {
			$("#tips").text("审核意见不可为空");
			return;
		} else {
			$("#tips").text("");
		}
		$.ajax({
			url : '/crm/auditrecord/insert',
			type : 'post',
			data : {
				uid : uid,
				tbAuditReportId : tbAuditReportId,
				auditClassify : auditClassify,
				auditType : auditType,
				auditStatus : auditStatus,
				auditRemark : auditRemark
			},
			success : function(obj) {
				console.log(obj);
				//模拟数据,当二审通过时,弹出合同添加model,向合同表中添加付费记录
				if(status==1 && flag==1){
				//判断合同表中是否有付款记录
			     $.post("/crm/contract/isPay", {uid:uid,times:times}, function(data){
			            if(!data.result) {
			               //判断flag标记是否为二审（1）
				           openInsertModel(uid);
			            } else {
			                greeting({
							msg : "操作成功!",
							confirm : function() {
								//window.location.reload();
								window.location ="/crm/auditrecord/"+page;
							}
						  });
			            }            
			        },'json');
				}else{
				greeting({
					msg : "操作成功!",
					confirm : function() {
						//window.location.reload();
						window.location ="/crm/auditrecord/"+page;
					}
				  });
				} 
			},
			error : function(obj) {
				console.log(obj);
			}
		});
	}    

$(function(){
    //模拟数据，插入合同
    $("#insertContract").click(function(){
        var uid = $("#contractUid").val();
        var createTime = $("#createTime").val();
        var isHande = $("#isHande").val();
        var payMoney = $("#payMoney").val();
        var remark = $("#remark").val();
        if(createTime == "") {
            $("#contract_tips").html("创建时间不可以为空！");
            return ;
        }else{
          $("#contract_tips").html("");
        }
          if(payMoney == "") {
            $("#payMoneyTips").html("付款金额不可以为空！");
            return ;
        }else{
          $("#payMoneyTips").html("");
        }
	        $.ajax({
				url : '/crm/contract/insert',
				type : 'post',
				data : {
					uid:uid,
			        createTime:createTime,
			        isHande:isHande,
			        payMoney:payMoney,
			        remark:remark
				},
				success : function(obj) {
				console.log(obj);
				if(obj.msg=="OK"){
				 $('#contractModal').modal('hide');
					greeting({
						msg : "操作成功!",
						confirm : function() {
							window.location.reload();
						}
					});
				  }else{
				   alert(obj.msg);
				  }
				},
				error : function(obj) {
					console.log(obj.msg);
					alert(obj.msg);
				}
			});
        
    });
    
});
</script>